<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 16:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>用户管理系统</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        table tr:nth-child(even) {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>用户列表</h2>
<!-- 查询表单 -->
<form action="index.jsp" method="get">
    <select name="conditionColumn">
        <option value="uid">用户ID</option>
        <option value="name">姓名</option>
        <option value="pid">身份证号</option>
        <option value="email">邮箱</option>
        <option value="phone">电话</option>
        <option value="identity">身份</option>
        <option value="is_registered">是否注册用户</option>
        <option value="password">密码</option>
    </select>
    <input type="text" name="conditionValue" placeholder="输入查询值">
    <input type="submit" value="查询">
</form>
<!-- 显示用户列表 -->
<table>
    <thead>
    <tr>
        <th>用户ID</th>
        <th>姓名</th>
        <th>身份证号</th>
        <th>邮箱</th>
        <th>电话</th>
        <th>身份</th>
        <th>是否注册用户</th>
        <th>密码</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        DB_User dbUser = new DB_User();
        String conditionColumn = request.getParameter("conditionColumn");
        if (conditionColumn == null) {
            conditionColumn = "";
        }
        String conditionValue = request.getParameter("conditionValue");
        if (conditionValue == null) {
            conditionValue = "";
        }
        List<String> returnList = new ArrayList<>();
        dbUser.find(conditionColumn, conditionValue, returnList);
        for (int i = 0; i < returnList.size(); i += 8) {
    %>
    <tr>
        <td><%= returnList.get(i) %></td>
        <td><%= returnList.get(i + 1) %></td>
        <td><%= returnList.get(i + 2) %></td>
        <td><%= returnList.get(i + 3) %></td>
        <td><%= returnList.get(i + 4) %></td>
        <td><%= returnList.get(i + 5) %></td>
        <td><%= returnList.get(i + 6) %></td>
        <td><%= returnList.get(i + 7) %></td>
        <td>
            <a href="editUser.jsp?uid=<%= returnList.get(i) %>">编辑</a>
            <a href="deleteUser.jsp?uid=<%= returnList.get(i) %>">删除</a>
        </td>
    </tr>
    <% } %>
    </tbody>
</table>
<!-- 添加用户表单，不需要添加是否注册用户信息 -->
<h2>添加用户</h2>
<form action="addUser.jsp" method="post">
    <label for="name">姓名:</label>
    <input type="text" id="name" name="name" required><br>
    <label for="password">密码:</label>
    <input type="text" id="password" name="password" required><br>
    <label for="pid">身份证号:</label>
    <input type="text" id="pid" name="pid" required><br>
    <label for="email">邮箱:</label>
    <input type="email" id="email" name="email" required><br>
    <label for="phone">电话:</label>
    <input type="text" id="phone" name="phone" required><br>
    <label for="identity">身份:</label>
    <select id="identity" name="identity" required>
        <option value="0">用户</option>
        <option value="1">管理员</option>
    </select><br>
    <input type="submit" value="添加用户">
</form>
</body>
</html>